// pages/complaint/complaint.js
// pages/euqip/equip.js
const {
  API,
  defaultPage,
  equipStatusEnum,
  CLINIC_MANAGER_CODE
} = require('../../utils/const.js');
const {
  formVaildate,
  checkCount
} = require('../../utils/formCheckUtil.js');
const {
  getRequest,
  postRequest
} = require('../../utils/request.js');
const re = require('../../utils/request.js');
const {
  EuipFormRoles
} = require('../../utils/rulse.js');
const {
  hasRole
} = require('../../utils/userUtil.js');
var app = getApp();

Page({
  data: {
    patients: [],
    selectedPatient: '',
    selectedPatientName: '',
    agreementLetterBaseInfos: [],
    selectedAgreementLetterBaseInfo: '',
    selectedAgreementLetterBaseInfoName: '',
    equipments: [],
    selectedEquipments: []
  },

   /**
   * Lifecycle function--Called when page load
   */
  onLoad(options) {
    const that = this;
    // 发起请求，获取数据

    getRequest(API.getPatientList).then(res => {
      that.setData({
        patients: res
      });
    });
  },

  onPatientChange: function(e) {
    const index = e.detail.value; // 获取选中的索引
    const selectedPatient = this.data.patients[index]; // 根据索引获取选中的患者对象

    // 设置选中的患者对象和名字
    this.setData({
      selectedPatient: selectedPatient,
      selectedPatientName: selectedPatient.patientName
    });
  },

  onSubmit() {
    if (this.data.selectedPatient) {
      const patientId = this.data.selectedPatient.patientId;
      const url = '/pages/getAgreementLetters/getAgreementLetters?patientId=' + patientId;
      wx.navigateTo({
        url: url
      });
    }
  }
});